﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HslCommunication.Profinet.Keyence;
using HslCommunication;
using DevExpress.XtraEditors;

namespace PLC_TEST
{
    public partial class Main : DevExpress.XtraEditors.XtraForm
    {
        public Main()
        {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(ipadd.Text)||string.IsNullOrEmpty(port.Text))
            {
                XtraMessageBox.Show("ip地址/端口号不能为空！");
                return;
            }
            KeyenceMcNet keyence_net = new KeyenceMcNet(ipadd.Text, int.Parse(port.Text));
            OperateResult connect = keyence_net.ConnectServer();
            if (connect.IsSuccess)
            {
                XtraMessageBox.Show("连接成功！");
            }
            else
            {
                XtraMessageBox.Show("连接失败！");
                return;
            }
            if (string.IsNullOrEmpty(comm.Text))
            {
                XtraMessageBox.Show("发送命令不能为空！");
                return;
            }
            short d100_short = keyence_net.ReadInt16("D100").Content;
            ushort d100_ushort = keyence_net.ReadUInt16("D100").Content;
            int d100_int = keyence_net.ReadInt32("D100").Content;
            uint d100_uint = keyence_net.ReadUInt32("D100").Content;
            long d100_long = keyence_net.ReadInt64("D100").Content;
            ulong d100_ulong = keyence_net.ReadUInt64("D100").Content;
            float d100_float = keyence_net.ReadFloat("D100").Content;
            double d100_double = keyence_net.ReadDouble("D100").Content;
            string d100_string = keyence_net.ReadString("D100", 10).Content;

            keyence_net.Write("D100", (short)5);
            keyence_net.Write("D100", (ushort)5);
            keyence_net.Write("D100", 5);
            keyence_net.Write("D100", (uint)5);
            keyence_net.Write("D100", (long)5);
            keyence_net.Write("D100", (ulong)5);
            keyence_net.Write("D100", 5f);
            keyence_net.Write("D100", 5d);
            // length should Multiples of 2
            keyence_net.Write("D100", "12345678");

            
        }
    }
}
